import request from '@/utils/request';

// 获取所有帖子（排除当前用户）
export function getPosts(page = 1, size = 10) {
  return request({
    url: 'posts',
    method: 'get',
    params: {
      page,
      size
    }
  });
}

// 创建新帖子
export function createPost(formData) {
  return request({
    url: 'posts',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    },

  });
}

// 获取帖子详情
export function getPostDetail(id) {
  return request({
    url: `posts/${id}`,
    method: 'get'
  });
}



// 点赞帖子
export function likePost(postId) {
  return request({
    url: `posts/${postId}/like`,
    method: 'post'
  });
}

// 取消点赞帖子
export function unlikePost(postId) {
  return request({
    url: `posts/${postId}/unlike`,
    method: 'post'
  });
}

// 获取帖子评论列表
export function getComments(postId, page = 0, size = 5) {
  return request({
    url: `comments/post/${postId}`,
    method: 'get',
    params: {
      page,
      size
    }
  });
}

// 添加评论
export function addComment(comment) {
  return request({
    url: 'comments',
    method: 'post',
    data: comment
  });
}

// 删除评论
export function deleteComment(commentId) {
  return request({
    url: `comments/${commentId}`,
    method: 'delete'
  });
}

// 获取用户帖子列表
export function getUserPosts(userId, page = 1, size = 10) {
  return request({
    url: `posts/user/${userId}`,
    method: 'get',
    params: {
      page,
      size
    }
  });
}
